import json
import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker


"""
现金流分析图
-利润表：归母净利润 （PARENT_NETPROFIT）
-利润表：营业收入（OPERATE_INCOME）
-现金流量表：经营活动现金流量净额  （NETCASH_OPERATE）
-现金流量表：经营活动现金流入 （TOTAL_OPERATE_INFLOW）
"""

def get_test_data():
    lirun_data = {}
    cash_data = {}
    with open("cash_data.json","r") as fd:
        filedata = fd.read()
        cash_data = json.loads(filedata)
    with open("lirun_data.json","r") as fd:
        filedata = fd.read()
        lirun_data = json.loads(filedata)
    return lirun_data, cash_data

def make_xdata(data, fieldname):
    result = []
    count = data["result"]["count"]
    _data = data["result"]["data"]
    for _ in _data:
        result.append(_[fieldname])
    result.reverse()
    return result

def make_stack_data(keyname, data):
    result = []
    return result
    
def makechart_liruncash(lirun_data, cash_data):
    c = (
        Line()
        .add_xaxis(make_xdata(lirun_data,"REPORT_DATE_NAME"))
        .add_yaxis("净利润", make_xdata(lirun_data, "PARENT_NETPROFIT"))
        .add_yaxis("经营活动现金流入", make_xdata(cash_data, "NETCASH_OPERATE"))
        .set_global_opts(title_opts=opts.TitleOpts(title="净利润现金流对比分析"))
        .render("净利润现金流对比分析.html")
    )

if __name__ == '__main__':
    lirun_data, cash_data = get_test_data()
    makechart_liruncash(lirun_data, cash_data)